#include "customkeysequenceedit.h"
#include <QDebug>
#include <QKeyEvent>

CustomKeySequenceEdit::CustomKeySequenceEdit(QWidget *parent)
    : QKeySequenceEdit(parent)
{
    //    this->setStyleSheet("QLineEdit{qproperty-alignment:AlignHCenter;}"); //设置文字居中
}

void CustomKeySequenceEdit::keyPressEvent(QKeyEvent *event)
{
    if (event->key() == Qt::Key_Backspace)
    {
        this->clear();
    }
    else
    {
        QKeySequenceEdit::keyPressEvent(event);
        QString strKeySequence = keySequence().toString().split(",").first();
        QKeySequence seq(QKeySequence::fromString(strKeySequence));
        setKeySequence(seq);
    }

    emit editingFinished();
}


//connect(ui->keySequenceEdit, &CustomKeySequenceEdit::editingFinished, this, [&](){
//    18          m_activedNum = 0;
//    19          ui->label->clear();
//    20
//        21         if (m_hotkey->setShortcut(ui->keySequenceEdit->keySequence()))
//        22         {
//        23               qDebug() << "hot key is register sucess!";
//        24         }
//    25         else
//        26         {
//        27             if (!ui->keySequenceEdit->keySequence().isEmpty())
//            28                 qDebug() << "hot key is register failed!";
//        29         }
//    30     });
